<?php $this->load->view('header'); ?>

<!-- Common Styles for the application --> 
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/resources/css/silk.css" />

<!-- overrides to base library --> 
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/css/GridFilters.css" /> 
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/css/RangeMenu.css" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/resources/js/ext_plugins/fileuploadfield/css/fileuploadfield.css"/> 
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/resources/js/ext_plugins/css/RowEditor.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/resources/js/ext_plugins/css/MultiSelect.css"/>
<!-- extensions section -->

<!-- Grid filters plugin -->
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/menu/RangeMenu.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/menu/ListMenu.js"></script> 

<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/GridFilters.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/filter/Filter.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/filter/StringFilter.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/filter/DateFilter.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/filter/ListFilter.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/filter/NumericFilter.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext_plugins/gridfilters/filter/BooleanFilter.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext_plugins/SearchField.js"></script>
<!-- end extensions section -->

<!-- my application -->
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/application/DocumentGrid.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/application/DocumentDetail.js"></script>

<script type="text/javascript">
//Application instance for showing user-feedback messages.
Ext.onReady( function() {
	var user = (myApp.userdata.username === undefined) ? myApp.userdata.roles : myApp.userdata.username;
	myApp.setAlert(myApp.STATUS_NOTICE, '<b><i>' + user + '</i></b><br/>Bienvenido a la secci&oacute;n de lectura');
});

//alert(access('acceso a descargar documentos 123'));
//console.log(USER_CONST);

cloneConfig = function (config) { 
	for (i in config) {
		if (typeof config[i] == 'object') { 
			this[i] = new cloneConfig(config[i]);
		} 
		else
			this[i] = config[i];
	}
};

//-------------------------------------------
// documentForm object initialization section

//create document.Form instance (@see assests/js/application/DocumentForm.js )
var documentDetail = new App.document.Detail();

/**
 * Construct a recordModel for an specific documentType
 *
 * @return an array containing the recordModel
 */
function buildRecordModelByDocumentType(documentType) {
	var fields = new Array();
	
	// add default fields
	fields = fields.concat([
		{name: 'title',  mapping: 'title'}, 
		{name: 'authors',  mapping: 'authors'}, 
		{name: 'documentType',  mapping: 'documentType'},
		{name: 'year',  mapping: 'year'}, 
		{name: 'pages',  mapping: 'pages'},
		{name: 'publishedin',  mapping: 'publishedin'},
		{name: 'abstract',  mapping: 'abstract'},
		{name: 'keywords',  mapping: 'keywords'},
		{name: 'files',  mapping: 'files'},
		]);	
	
	switch( documentType ) {
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_THESIS:
			fields = fields.concat([
			    {name: 'tutors', mapping: 'tutors'},
			    {name: 'department', mapping: 'department'},
			    {name: 'faculty', mapping: 'faculty'},
			    {name: 'knowledgearea', mapping: 'knowledgearea'}
			    ]);
			break;
		
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_MASTER_THESIS:
			fields = fields.concat([
			    {name: 'tutors', mapping: 'tutors'},
			    {name: 'department', mapping: 'department'},
			    {name: 'faculty', mapping: 'faculty'},
			    {name: 'knowledgearea', mapping: 'knowledgearea'}
			    ]);
			break;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_PHD_THESIS:
			fields = fields.concat([
			    {name: 'tutors', mapping: 'tutors'},
			    {name: 'department', mapping: 'department'},
			    {name: 'faculty', mapping: 'faculty'},
			    {name: 'knowledgearea', mapping: 'knowledgearea'}
			    ]);
			break;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_MAGAZINE_ARTICLE:
			fields = fields.concat([
			    {name: 'city', mapping: 'city'}
			    ]);
			break;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_BOOK:
			fields = fields.concat([
			    {name: 'city', mapping: 'city'},
			    {name: 'edition', mapping: 'edition'},
			    {name: 'editors', mapping: 'editors'},
			    {name: 'publisher', mapping: 'publisher'},
			    {name: 'knowledgearea', mapping: 'knowledgearea'}
			    ]);
			break;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_ENCYCLOPEDIA:
			fields = fields.concat([
			    {name: 'edition', mapping: 'edition'},
			    {name: 'publisher', mapping: 'publisher'},
			    {name: 'series_number', mapping: 'series_number'}
			    ]);
			break;
	}
	return fields;
}

function buildTplMarkupByDocumentType(documentType) {
	var tplMarkup = new Array();

	var documentTypeString = documentTypeRenderer(documentType);
	
	// add default fields
	tplMarkup = tplMarkup.concat([
		'<div id="document-details">',
		'<p>'+documentTypeString+'</p>',
		'<h2 class="title">{title}</h2>',
		'<p><b>Autore(s)</b>: {authors}</p>',
		'<p><b>A&ntilde;o</b>: {year}</p>',
		'<p><b>P&aacute;ginas</b>: {pages}</p>',
		'<p><b>Publicado en</b>: {publishedin}</p>',
		'<p><b>Resumen</b>: {abstract}</p>',
		'<p><b>Keywords</b>:<br/> {keywords}</p>'
		]);	
	
	switch( documentType ) {
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_THESIS:
			tplMarkup = tplMarkup.concat([
				'<p><b>Tutor(es)</b>: {tutors}</p>',	
				'<p><b>Departamento</b>: {department}</p>',
				'<p><b>Facultad</b>: {faculty}</p>',
				'<p><b>&Aacute;rea del conocimiento</b>: {knowledgearea}</p>'
        ]);	
			break;
		
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_MASTER_THESIS:
			tplMarkup = tplMarkup.concat([
              				'<p><b>Tutor(es)</b>: {tutors}</p>',	
              				'<p><b>Departamento</b>: {department}</p>',
              				'<p><b>Facultad</b>: {faculty}</p>',
              				'<p><b>&Aacute;rea del conocimiento</b>: {knowledgearea}</p>'
                      ]);	
			break;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_PHD_THESIS:
			tplMarkup = tplMarkup.concat([
              				'<p><b>Tutor(es)</b>: {tutors}</p>',	
              				'<p><b>Departamento</b>: {department}</p>',
              				'<p><b>Facultad</b>: {faculty}</p>',
              				'<p><b>&Aacute;rea del conocimiento</b>: {knowledgearea}</p>'
                      ]);	
			break;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_MAGAZINE_ARTICLE:
			tplMarkup = tplMarkup.concat([
				'<p><b>Ciudad</b>: {city}</p>'
			]);
			break;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_BOOK:
			tplMarkup = tplMarkup.concat([
				'<p><b>Ciudad</b>: {city}</p>',
				'<p><b>Edici&oacute;n</b>: {edition}</p>',
				'<p><b>Editore(s)</b>: {editors}</p>',
				'<p><b>Publicador</b>: {publisher}</p>',
				'<p><b>&Aacute;rea del conocimiento</b>: {knowledgearea}</p>'
			]);
			break;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_ENCYCLOPEDIA:
			tplMarkup = tplMarkup.concat([
			              				'<p><b>Edici&oacute;n</b>: {edition}</p>',
			              				'<p><b>Publicador</b>: {publisher}</p>',
			              				'<p><b>Numero de serie</b>: {series_number}</p>'
			              			]);
			break;
	}

	if (myApp.userdata.roles != USER_CONST.ROLE_ANONYMOUS_USER) {
  	tplMarkup = tplMarkup.concat([
  		'<p><b>Archivos PDF</b>:<br/>',
  		'<tpl for="files">',
  	    '<a href="archivo/open/{name}" target="_blank">{name}</a><br/>',
  		'</tpl></p>',
  	]);
	}

	tplMarkup = tplMarkup.concat(['</div>']);
	                          	
	return tplMarkup;
}

//-------------------------------------------
// grid object initialization section

var documentRecord = Ext.data.Record.create([
	{name: 'id',  mapping: 'id'	},
	{name: 'authors',  mapping: 'authors'	}, 
	{name: 'title',  mapping: 'title'}, 
	{name: 'documentType',  mapping: 'documentType'},
	{name: 'year',  mapping: 'year'}, 
	{name: 'pages',  mapping: 'pages'},
	{name: 'publishedin',  mapping: 'publishedin'},
  {name: 'abstract',  mapping: 'abstract'},
  {name: 'keywords',  mapping: 'keywords'},
  {name: 'created_at',  mapping: 'created_at'/*, type: 'date', dateFormat: 'm/d/Y'*/},
  {name: 'updated_at',  mapping: 'updated_at', type: 'date', dateFormat: 'm/d/Y'},
]);

// configuring the grid filter
var filters = new Ext.ux.grid.GridFilters({
    // encode and local configuration options defined previously for easier reuse
    encode: false, // json encode the filter query
    local: myApp.filterType,   // defaults to false (remote filtering)
    menuFilterText: 'Filtrar',
    filters: [{
        type: 'numeric',
        dataIndex: 'id'
    }, {
        type: 'string',
        dataIndex: 'authors'
        //disabled: true
    }, {
        type: 'string',
        dataIndex: 'title'
    }, {
        type: 'list',
        dataIndex: 'documentType',
        options: [
        	[myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_THESIS, 						myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_THESIS],
        	[myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_MASTER_THESIS, 		myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_MASTER_THESIS],
        	[myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_PHD_THESIS, 				myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_PHD_THESIS],
        	[myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_MAGAZINE_ARTICLE, 	myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_MAGAZINE_ARTICLE],
        	[myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_BOOK, 							myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_BOOK],
        	[myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_ENCYCLOPEDIA, 			myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_ENCYCLOPEDIA]
        ],
        phpMode: true
    }, {
    		type: 'string',
        dataIndex: 'year'
    }, {
    		type: 'string',
        dataIndex: 'pages'
    }, {
    		type: 'string',
        dataIndex: 'publishedin'
    }, {
    		type: 'string',
        dataIndex: 'abstract'
    }, {
        type: 'string',
        dataIndex: 'keywords'
    }]
});  

//Create HttpProxy instance.  Notice new configuration parameter "api" here instead of load.  However, you can still use
//the "url" paramater -- All CRUD requests will be directed to your single url instead.
var documentProxy = new Ext.data.HttpProxy({
  api: {
		read: BASE_URL + 'documents',
		create: BASE_URL + 'documents/create', 
		update: BASE_URL + 'documents/update',
		destroy: BASE_URL + 'documents/delete'
	},
	method: 'POST'
});

//Typical JsonReader.  Notice additional meta-data params for defining the core attributes of your json-response
var documentReader = new Ext.data.JsonReader({
    totalProperty: 'documents',
    successProperty: 'success',
    messageProperty: 'message',  // <-- New "messageProperty" meta-data
    idProperty: 'id',
    root: 'data',
    fields: documentRecord
});

//Typical Store collecting the Proxy, Reader and Writer together.
var documentGroupingStore = new Ext.data.GroupingStore({
		proxy: documentProxy,
    reader: documentReader,
    sortInfo:{field: 'created_at', direction: "DESC"},
    //sortInfo:{field: 'id', direction: "DESC"},
    groupField:'documentType',
});

// load the store immeditately
documentGroupingStore.load();

/**
 * Handler specified for the 'Available' column renderer
 * @param {Object} value
 */
function formatDateRenderer(value){
	if (value !== undefined ) {
		var dt = new Date();
		dt = Date.parseDate(value, "Y-m-d H:i:s", true);
	  return dt.format('m/d/Y');
	}
	else {
		return '';
	}
}

/**
 * Handler specified for the 'Status' column renderer for the UserManager 
 * @param {Object} value
 */
function userStatusRenderer(value){
		if (value !== undefined ) {
			return value == 0 ? 'No' : 'Si';
		}
		else {
			return '';
		}
	}
 
/**
 * Handler for the documentType column renderer
 * @param {Object} value
 */ 
function documentTypeRenderer(value) {
	var documentType = parseInt(value);
	
	switch (documentType) {
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_THESIS: 
			return myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_THESIS;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_MASTER_THESIS: 
			return myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_MASTER_THESIS;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_PHD_THESIS: 
			return myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_PHD_THESIS;
			
		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_MAGAZINE_ARTICLE: 
			return myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_MAGAZINE_ARTICLE;

		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_BOOK: 
			return myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_BOOK;

		case myApp.DOCUMENT_TYPES_INTVALUE.DOCUMENT_TYPE_ENCYCLOPEDIA: 
			return myApp.DOCUMENT_TYPES_STRINGVALUE.DOCUMENT_TYPE_ENCYCLOPEDIA;
	}
}

// create the row selction model
var rowSelectionModel = new Ext.grid.RowSelectionModel({ 
	singleSelect: true
/*
	listeners: {
		rowselect: { 
			fn: function(sm,index,record) {
				Ext.Msg.alert('You Selected',record.data.title);
			}
		}
	}
	*/
});

// Let's pretend we rendered our grid-columns with meta-data from our ORM framework. 
// In our case documents doctrine record
// {data source} == mapping ==> {data store} == dataIndex ==> {ColumnModel}
var columnModel = new Ext.grid.ColumnModel([
	{header: "Id", dataIndex: 'id', sortable: true, filterable: true, hidden: true},
	{header: "Autor", width: 120, dataIndex: 'authors', sortable: true, filterable: true},
	{header: "T&iacute;tulo", width: 180, dataIndex: 'title', sortable: true, filterable: true},
	{header: "A&ntilde;o", width: 115, dataIndex: 'year', sortable: true, filterable: true},
	{header: "P&aacute;ginas", width: 100, dataIndex: 'pages', sortable: true},
	{header: "Publicado en", width: 100, dataIndex: 'publishedin', sortable: true, filterable: true},
	{header: "Adicionado", width: 100, dataIndex: 'created_at', sortable: true, renderer: formatDateRenderer},
	{header: "Tipo de Documento", width: 100, dataIndex: 'documentType', sortable: true, renderer: documentTypeRenderer, filterable: true}
]);

var documentDetailProxy = new Ext.data.HttpProxy({
	  api: {
			read: BASE_URL + 'documents/getDocumentDetailed'
		},
		method: 'POST'
	});

//create document.Grid instance (@see assests/js/application/DocumentGrid.js)
var documentGrid = new App.document.Grid({
    //renderTo: 'user-grid',
    //store: documentStore,
    store: documentGroupingStore,
    //columns: documentColumns,
    cm: columnModel,
		sm: rowSelectionModel,
		application: myApp,
		//linkedForm: documentForm,
		loadMask: true, 

		// group view to visualize the header in each group
		view: new Ext.grid.GroupingView({
    	forceFit:true,
      groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Documentos" : "Documento"]})',
      showGroupsText: 'Mostrar en Grupos',
      groupByText: 'Agrupar por este Campo',
      columnsText: 'Columnas',
      sortAscText: 'Ordena Ascedentemente',
      sortDescText: 'Ordenar Descendentemente'
    }),

    // add the plugin filters to the grid
    plugins: [filters],

    listeners: {
        rowclick: function(g, index, ev) {
    				// si existe algun record que se esta editando y no se ha salvado
    				// preguntamos si queremos salvarlo o no en caso de que la opcion
    				// autosave este desabilitada
    				if(myApp.gridSelectedIndex != index) {
							myApp.gridSelectedIndex = index;
				      var record = g.store.getAt(index);

				      // convert documentType value from string to int
				      var documentType = parseInt(record.data.documentType);
				      // build the record model for the type of documentType
				      var recordModel = buildRecordModelByDocumentType(documentType);
				      // create the Reader using the specific recordModel
				      var documentDetailReader = new Ext.data.JsonReader({
				    	    totalProperty: 'details',
				    	    successProperty: 'success',
				    	    messageProperty: 'message',  
				    	    idProperty: 'id',
				    	    root: 'data',
				    	    fields: recordModel
				    	});

				    	// typical Store collecting the Proxy, Reader and Writer together.
				    	var documentDetailStore = new Ext.data.Store({
				    	    reader: documentDetailReader,
				    	    proxy: documentDetailProxy,
//				    	    listeners: { 
//				    	    	load: function( /*Store*/ store, /*Ext.data.Record[]*/ records, /*Object*/ options ) {
//				    	    		console.log(records);
//				    	    		console.log(options);
//				    	    	}
//				    			}
				    	});

				    	var parameters = {id: parseInt(record.id), documentType: documentType};
				    	var string = Ext.util.JSON.encode(parameters);
				    	documentDetailStore.setBaseParam('parameters', string);
			        var mask = new Ext.LoadMask(Ext.getBody(), {
				        msg: 'Cargando detalles del documento...', 
				        removeMask: true, 
				        store: documentDetailStore
				      });
			            
	            var result = documentDetailStore.load({
	            	callback: function(r, options, success) {
	            		if( success ) {
	            			var detailedRecord = documentDetailStore.getById(record.id);
	            			documentDetail.setTplMarkup(buildTplMarkupByDocumentType(documentType));
	            	    documentDetail.updateDetail(detailedRecord.data);
	            		}
	            		else {
	            			Ext.Msg.alert('AJAX - Fallo en pedido', this.reader.jsonData.message);
	            		}
	            	}
	            });
    				}
        }     
    }
});

// end of grid initialization section
//------------------------------------------------

var mainToolBar = new Ext.Toolbar({
    items: [
				 '->', {
		        iconCls: 'icon-user-login',
		        text: 'Login',
		        handler: doLogin,
		        hidden: isUserLoggedIn()
		        //height: 43
	        }, {
		        iconCls: 'icon-user-logout',
		        text: 'Cerrar sesi&oacute;n',
		        handler: doLogout,
		        hidden: !isUserLoggedIn()
		        //height: 43
    }]
});

var viewport = new Ext.Viewport({
	layout: 'border', 
	renderTo: Ext.getBody(),
	items: [ 
  	{ region: 'north', 
  	 	autoHeight: true, 
  	 	height: 100, 
  	 	border: false,
      html: '<div id="header">SISMAPC <span style="font-size:12px;">Sistema para la gestion de la Producci&oacute;n Cient&iacute;fica en la UNISS.</span></div>',
      margins: '0 0 3 0', 
      style: 'border-bottom: 4px solid #4c72a4;' 
    }, {
    	//xtype: 'documentdetail',
			//itemId: 'detailPanel',
			title: 'Detalles del Documento',
    	region: 'east',
      collapsible: true,
      split: true,
      width: 400, // give east and west regions a width
      minSize: 175,
      maxSize: 600,
      margins: '0 3 3 0',
      cmargins:'0 3 3 3',
      layout: 'fit', // specify layout manager for items
      items: [documentDetail]
    }, {
    	id: 'content-panel', 
    	region: 'center', 
    	layout: 'fit', 
    	margins: '0 0 3 3',
      //activeItem: 0, 
      //border: true, 
      tbar:mainToolBar, 
      items: [documentGrid]
    }
  ]});

//centralized listening of DataProxy events "beforewrite", "write" and "writeexception"
//upon Ext.data.DataProxy class.  This is handy for centralizing user-feedback messaging into one place rather than
//attaching listenrs to EACH Store.
//
//Listen to all DataProxy beforewrite events
//
Ext.data.DataProxy.addListener('beforewrite', function(proxy, action) {
	myApp.setAlert(myApp.STATUS_NOTICE, "Ejecuntando la acci&oacute;n: " + action);
});

/*
Ext.data.DataProxy.addListener('load', function(proxy, action) {
	myApp.setAlert(App.STATUS_NOTICE, "Before " + action);
});
*/

//all write events
//
Ext.data.DataProxy.addListener('write', function(proxy, action, result, res, rs) {
	if( /*action == "update" || */action == "create" ) {
/*
		documentGrid.store.reload({
			action: action, record: result[0]
			});
		*/	
	}
	
	myApp.setAlert(myApp.STATUS_OK, action + ': ' + res.message);
});

//all exception events
//
Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) {
	myApp.setAlert(App.STATUS_ERROR, "Algo err&oacute;neo ha ocurrido mientras se executaba la acci&oacute;n: " + action);
});

// Customize the default text for MessageBox
Ext.MessageBox.buttonText.yes = 'Si';
Ext.MessageBox.buttonText.cancel = 'Cancelar';

viewport.show();
</script>

<?php $this->load->view('footer'); ?>